package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.MemberBindRecordDto;
import edu.suda.xsap.dto.MemberDto;
import edu.suda.xsap.dto.convert.MemberConvert;
import edu.suda.xsap.entity.Member;
import edu.suda.xsap.entity.MemberBindRecord;
import edu.suda.xsap.entity.vo.IdVo;
import edu.suda.xsap.entity.vo.MemberCardVo;
import edu.suda.xsap.entity.vo.MemberVo;
import edu.suda.xsap.mapper.MemberBindRecordMapper;
import edu.suda.xsap.mapper.MemberCardVoMapper;
import edu.suda.xsap.mapper.MemberMapper;
import edu.suda.xsap.mapper.MemberVoMapper;
import edu.suda.xsap.service.MemberBindRecordService;
import edu.suda.xsap.service.MemberCardService;
import edu.suda.xsap.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MemberServiceImpl implements MemberService {
@Autowired
private MemberMapper memberMapper;
@Autowired
private MemberConvert memberConvert;
@Autowired
private MemberVoMapper memberVoMapper;
@Autowired
private MemberCardVoMapper memberCardVoMapper;
    @Override
    public void delete(Integer id) {
        memberMapper.delete(id);
    }

    @Override
    public List<MemberDto> findAll() {
        List<Member> members=memberMapper.findAll();
        return memberConvert.toDtoList(members);
    }

    @Override
    public MemberDto findById(Integer id) {
        return memberConvert.toDto(memberMapper.findById(id));
    }



    @Override
    public IdVo save(Member member) {
        memberMapper.save(member);
        return IdVo.builder().id(member.getId()).build();
    }

    @Override
    public void update(Member member) {
        memberMapper.update(member);
    }

    @Override
    public List<MemberVo> findByLimit(Integer limit, Integer offset) {
        return memberVoMapper.findByLimit(limit,offset);
    }


    @Override
    public Integer findCount() {
        return memberMapper.findCount();
    }

    @Override
    public List<MemberCardVo> findCardByMemberId(Integer memberId) {
        return memberCardVoMapper.findByMemberId(memberId);
    }

    @Override
    public Integer changeStatus(Integer id) {
        memberMapper.changeStatus(id);
        return memberMapper.findStatus(id);
    }
}
